package com.bookcode.service;

import com.bookcode.dao.SignRecorderRepository;
import com.bookcode.entity.SignRecorder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SignRecorderService {
    @Autowired
    SignRecorderRepository signRecorderRepository;
    public boolean isSigned(Long courseId, Long studentId) {
        List<SignRecorder> signRecorders = signRecorderRepository.findAll();
        if (!signRecorders.isEmpty()) {
            System.out.println(signRecorders.size());
            int i = 0;
            //for
            for (i = 0; i < signRecorders.size(); i++)
                if (courseId.equals(signRecorders.get(i).getCourseId())) {
                    System.out.println(signRecorders.get(i).getStudentId());
                    System.out.println(studentId);
                    if (studentId.equals(signRecorders.get(i).getStudentId())) {
                        System.out.println("strue");
                        return true;
                    }//if
                }//if

        }//if
        return false;
    }
    public void save(SignRecorder signRecorder) {
        signRecorderRepository.save(signRecorder);
    }

}
